package com.atguigu.async;

import com.atguigu.exception.SleepUtils;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.function.Function;
import java.util.function.Supplier;

public class FutureDemo7 {
    public static void main(String[] args) throws Exception{
        runAsync1();
        System.out.println("main");
        SleepUtils.sleep(3);
    }

    public static void runAsync1() throws ExecutionException, InterruptedException {
        CompletableFuture<String> supplyAsync = CompletableFuture.supplyAsync(()->{
            System.out.println(Thread.currentThread().getName()+"你好supplyAsync");
            SleepUtils.sleep(1);
            return "java0317";
        });
        CompletableFuture<String> thenApply = supplyAsync.thenApply((acceptValue)->{
            System.out.println(Thread.currentThread().getName() + "第一个接收thenApply返回值" + acceptValue);

            return "thenApply" + acceptValue;
        });

        CompletableFuture<String> thenApply2 = supplyAsync.thenApply((acceptValue)->{

            System.out.println(Thread.currentThread().getName() + "第二个接收thenApply2返回值" + acceptValue);

            return "thenApply2" + acceptValue;
        });
        System.out.println(thenApply.get());
        System.out.println(thenApply2.get());
    }

}
